package com.validator;


import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Arrays;

/**
 * @author zdh
 */
public class RangeConstraintValidator implements ConstraintValidator<RangeCheck, Integer> {
    private RangeCheck rangeCheck;

    @Override
    public void initialize(RangeCheck rangeCheck) {
        this.rangeCheck=rangeCheck;
    }

    @Override
    public boolean isValid(Integer integer, ConstraintValidatorContext context) {
        if(integer==null){
            return false;
        }
        int[] range = rangeCheck.range();
        return Arrays.stream(range).anyMatch(integer::equals);
    }
}

